<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../../../favicon.ico">

    <title>Dashboard Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link th:href="@{/webjars/bootstrap/4.3.1/css/bootstrap.css}" href="../../../../dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="dashboard.css" rel="stylesheet" th:href="@{/assets/css/dashboard.css}">
  </head>

  <body>
    <!--引入抽取的topbar-->
    <!--模板名：会使用thymeleaf的前后缀配置规则进行解析-->
    <div th:replace="commons/bar :: topbar">
    </div>

    <div class="container-fluid">
      <div class="row">
        <!--映入侧边栏-->
        <div th:replace="commons/bar :: #sidebar(activeUri = 'emps')">
        </div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
          <!--需要区分添加还是修改页面-->
          <form th:action="@{/emp}" method="post" th:method="post">
            <!--
              html原生发送put方式
              1.SpringMvc中配置HiddenHttpMethodFilter
              2.页面穿件一个psot表单
              3.创建一个input项，name='_method';值就是我们指定请求的方式

            -->
            <input type="hidden" name="_method" value="put" th:if="${emp != null}"/>
            <input type="hidden" name="id" value="put" th:value="${emp != null} ? ${emp.id}"/>
            <div class="form-group">
              <label for="last-name">LastName</label>
              <input type="text" class="form-control" name="lastName" id="last-name" placeholder="zhangsan" th:value="${emp != null} ? ${emp.lastName}">
            </div>
            <div class="form-group">
              <label for="email">Email</label>
              <input type="email" class="form-control" name="email" id="email" placeholder="zhangsan@fenqing168.com" th:value="${emp != null} ? ${emp.email}">
            </div>
            <div class="form-group">
              <label>Gender</label>
              <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="gender" id="man" value="1" th:checked="${emp != null} ? ${emp.gender == 1}">
                <label class="form-check-label" for="man">男</label>
              </div>
              <div class="form-check form-check-inline">
                <input class="form-check-input" type="radio" name="gender" id="woman" value="0" th:checked="${emp != null} ? ${emp.gender == 0}">
                <label class="form-check-label" for="woman">女</label>
              </div>
            </div>
            <div class="form-group">
              <label for="department">department</label>
              <select class="form-control form-control-lg" id="department" name="department.id">
                <option th:value="${dept.id}" th:each="dept:${depts}" th:text="${dept.departmentName}" th:selected="${emp != null} ? ${emp.department.id == dept.id}">1</option>
              </select>
            </div>
            <div class="form-group">
              <label for="birth">Birth</label>
              <input type="text" class="form-control" name="birth" id="birth" placeholder="2019-10-10" th:value="${emp != null} ? ${#dates.format(emp.birth, 'yyyy-MM-dd')}">
            </div>
            <div class="form-group">
              <input type="submit" class="btn btn-primary" value="添加" th:value="${emp == null ? '添加' : '修改'}">
            </div>
          </form>
        </main>
      </div>
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script th:src="@{/webjars/jquery/3.4.1/jquery.slim.min.js}" src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script>window.jQuery || document.write('<script  src="[[@{/webjars/jquery/3.4.1/jquery.slim.min.js}]]"><\/script>')</script>
    <script th:src="@{/webjars/popper.js/1.15.0/popper.min.js}" src="../../../../assets/js/vendor/popper.min.js"></script>
    <script th:src="@{/webjars/bootstrap/4.3.1/js/bootstrap.js}" src="../../../../dist/js/bootstrap.min.js"></script>

    <!-- Icons -->
    <script th:src="@{/assets/js/feather.min.js}" src="https://unpkg.com/feather-icons/dist/feather.min.js"></script>
    <script>
      feather.replace()
    </script>

    <!-- Graphs -->
    <script th:src="@{/webjars/Chart.js/2.5.0/dist/Chart.min.js}" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script>
    <script>
      var ctx = document.getElementById("myChart");
      var myChart = new Chart(ctx, {
        type: 'line',
        data: {
          labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
          datasets: [{
            data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
            lineTension: 0,
            backgroundColor: 'transparent',
            borderColor: '#007bff',
            borderWidth: 4,
            pointBackgroundColor: '#007bff'
          }]
        },
        options: {
          scales: {
            yAxes: [{
              ticks: {
                beginAtZero: false
              }
            }]
          },
          legend: {
            display: false,
          }
        }
      });
    </script>
  </body>
</html>
